"""View file for CheatCheetah application"""
import wx
import os
from pdfgenerator import Cheatcheetah


class CheatCheetahUI(wx.Frame):
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, wx.ID_ANY, "Cheat Cheetah")

        #Construct list of cheat sheets
        sheets = []
        for filename in os.listdir("cheatsheets"):
            if filename.endswith(".xml"):
                sheets.append(filename[:-4])

        self.panel = wx.Panel(self)
        self.initUI(sheets)
        self.SetBackgroundColour('white')
        self.Fit()

    def initUI(self, sheets):
        """Initialization of the UI"""

        gridbagsizer = wx.GridBagSizer(5,9)

        text1 = wx.StaticText(self.panel, wx.ID_ANY, label="Cheat Cheetah", style=wx.ALIGN_CENTRE)
        gridbagsizer.Add(text1, pos=(0, 0), span=(2, 9), flag=wx.EXPAND | wx.CENTER)

        text2 = wx.StaticText(self.panel, wx.ID_ANY, label='Select sheet')
        gridbagsizer.Add(text2, pos=(2, 1), span=(1, 3), flag=wx.EXPAND)

        combo = wx.ComboBox(self.panel, 2, choices=sheets, style=wx.CB_READONLY)
        gridbagsizer.Add(combo, pos=(2, 5), span=(1, 3), flag=wx.EXPAND)

        generateButton = wx.Button(self.panel, 1, 'Generate')
        gridbagsizer.Add(generateButton, pos=(3, 3), span=(1, 3), flag=wx.EXPAND)

        editButton = wx.Button(self.panel, 3, 'Edit')
        gridbagsizer.Add(editButton, pos=(4, 3), span=(1, 3), flag=wx.EXPAND)

        gridbagsizer.AddGrowableCol(5, 1)

        self.panel.Bind(wx.EVT_BUTTON, self.buttonPushed)
        self.panel.SetSizerAndFit(gridbagsizer)
        self.panel.SetMinSize(gridbagsizer.GetMinSize())

    def buttonPushed(self, event):
        Cheatcheetah.generate(self.FindWindowById(2).GetValue())


